home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / X / Xserver / XLayerUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.2 KB  |  152 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* $Revision: 1.5 $ */
  18. #include <stdio.h>
  19. #include "XLayerUtil.h"
  20.  
  21. static Bool layersRead;
  22. static Atom overlayVisualsAtom;
  23. static OverlayInfo **overlayInfoPerScreen;
  24. static int *numOverlaysPerScreen;
  25.  
  26. XLayerVisualInfo *
  27. XGetLayerVisualInfo(display, lvinfo_mask, lvinfo_template, nitems_return)
  28.    Display *display;
  29.    long lvinfo_mask;
  30.    XLayerVisualInfo *lvinfo_template;
  31.    int *nitems_return;
  32. {
  33.    XVisualInfo *vinfo;
  34.    XLayerVisualInfo *layerInfo;
  35.    Window root;
  36.    Status status;
  37.    Atom actualType;
  38.    unsigned long sizeData, bytesLeft;
  39.    int actualFormat, numVisuals, numScreens, count, i, j;
  40.  
  41.    vinfo = XGetVisualInfo(display, lvinfo_mask&VisualAllMask,
  42.       &lvinfo_template->vinfo, nitems_return);
  43.    if(vinfo == NULL)
  44.       return NULL;
  45.    numVisuals = *nitems_return;
  46.    if(layersRead == False) {
  47.       overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True);
  48.       if(overlayVisualsAtom != None) {
  49.          numScreens = ScreenCount(display);
  50.          overlayInfoPerScreen = (OverlayInfo**) malloc(numScreens*sizeof(OverlayInfo*));
  51.          numOverlaysPerScreen = (int*) malloc(numScreens*sizeof(int));
  52.          if(overlayInfoPerScreen != NULL && numOverlaysPerScreen != NULL) {
  53.             for(i=0; i<numScreens; i++) {
  54.                root = RootWindow(display, i);
  55.                status = XGetWindowProperty(display, root, overlayVisualsAtom,
  56.                   0L, (long)10000, False, overlayVisualsAtom, &actualType, &actualFormat,
  57.                   &sizeData, &bytesLeft, (char**) &overlayInfoPerScreen[i]);
  58.                if(status!=Success || actualType!=overlayVisualsAtom ||
  59.                  actualFormat!=32 || sizeData<4)
  60.                   numOverlaysPerScreen[i] = 0;
  61.                else
  62.                   numOverlaysPerScreen[i] = sizeData / (sizeof(OverlayInfo)/4);
  63.             }
  64.             layersRead = True;
  65.          } else {
  66.             if(overlayInfoPerScreen != NULL) free(overlayInfoPerScreen);
  67.             if(numOverlaysPerScreen != NULL) free(numOverlaysPerScreen);
  68.          }
  69.       }
  70.    }
  71.    layerInfo = (XLayerVisualInfo*) malloc(numVisuals * sizeof(XLayerVisualInfo));
  72.    if(layerInfo == NULL) {
  73.       XFree(vinfo);
  74.       return NULL;
  75.    }
  76.    count = 0;
  77.    for(i=0; i<numVisuals; i++) {
  78.       XVisualInfo *pVinfo;
  79.       int screen;
  80.       OverlayInfo *overlayInfo;
  81.  
  82.       pVinfo = &vinfo[i];
  83.       screen = pVinfo->screen;
  84.       overlayInfo = NULL;
  85.       if(layersRead) {
  86.          for(j=0; j<numOverlaysPerScreen[screen]; j++)
  87.             if(pVinfo->visualid == overlayInfoPerScreen[screen][j].overlay_visual) {
  88.                overlayInfo = &overlayInfoPerScreen[screen][j];
  89.            break;
  90.             }
  91.       }
  92.       if(lvinfo_mask & VisualLayerMask)
  93.          if(overlayInfo == NULL) {
  94.             if(lvinfo_template->layer != 0) continue;
  95.          } else
  96.             if(lvinfo_template->layer != overlayInfo->layer) continue;
  97.       if(lvinfo_mask & VisualTransparentType)
  98.          if(overlayInfo == NULL) {
  99.             if(lvinfo_template->type != None) continue;
  100.          } else
  101.             if(lvinfo_template->type != overlayInfo->transparent_type) continue;
  102.       if(lvinfo_mask & VisualTransparentValue)
  103.          if(overlayInfo == NULL)
  104.             /* non-overlay visuals have no sense of TransparentValue */
  105.             continue;
  106.          else
  107.             if(lvinfo_template->value != overlayInfo->value) continue;
  108.       layerInfo[count].vinfo = *pVinfo;
  109.       if(overlayInfo == NULL) {
  110.          layerInfo[count].layer = 0;
  111.          layerInfo[count].type = None;
  112.          layerInfo[count].value = 0; /* meaningless */
  113.       } else {
  114.          layerInfo[count].layer = overlayInfo->layer;
  115.          layerInfo[count].type = overlayInfo->transparent_type;
  116.          layerInfo[count].value = overlayInfo->value;
  117.       }
  118.       count++;
  119.    }
  120.    XFree(vinfo);
  121.    *nitems_return = count;
  122.    if(count == 0) {
  123.       XFree(layerInfo);
  124.       return NULL;
  125.    } else
  126.       return layerInfo;
  127. }
  128.  
  129. Status
  130. XMatchLayerVisualInfo(display, screen, depth, class, layer, lvinfo_return)
  131. Display *display;
  132. int screen, depth, class, layer;
  133. XLayerVisualInfo *lvinfo_return;
  134. {
  135.    XLayerVisualInfo *lvinfo;
  136.    XLayerVisualInfo lvinfoTemplate;
  137.    int nitems;
  138.  
  139.    lvinfoTemplate.vinfo.screen = screen;
  140.    lvinfoTemplate.vinfo.depth = depth;
  141.    lvinfoTemplate.vinfo.class = class;
  142.    lvinfoTemplate.layer = layer;
  143.    lvinfo = XGetLayerVisualInfo(display,
  144.       VisualScreenMask|VisualDepthMask|VisualClassMask|VisualLayerMask,
  145.       &lvinfoTemplate, &nitems);
  146.    if(lvinfo != NULL && nitems > 0) {
  147.       *lvinfo_return = *lvinfo;
  148.       return 1;
  149.    } else
  150.       return 0;
  151. }
  152.